package org.jeecg.modules.system.service.impl;

import org.jeecg.modules.system.entity.SysAppVersion;
import org.jeecg.modules.system.mapper.SysAppVersionMapper;
import org.jeecg.modules.system.service.ISysAppVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: app版本管理
 * @Author: jeecg-boot
 * @Date:   2019-12-02
 * @Version: V1.0
 */
@Service
public class SysAppVersionServiceImpl extends ServiceImpl<SysAppVersionMapper, SysAppVersion> implements ISysAppVersionService {

    @Autowired
    private SysAppVersionMapper sysAppVersionMapper;

    @Override
    public SysAppVersion getNewVersion(String os, Integer currentVersion) {
        if (currentVersion == null) {
            currentVersion = -1;
        }
        List<SysAppVersion> list = sysAppVersionMapper.findByOsVersion(os,currentVersion);
        if (list == null || list.isEmpty())
            return null;
        SysAppVersion appVersion = list.remove(0);
        //判断从上次版本到最新版本之间是否有强制更新标志,有的话就提示强制更新
        if (!appVersion.getUpdateForce()) {
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).getUpdateForce()) {
                    appVersion.setUpdateForce(list.get(i).getUpdateForce());
                    break;
                }
            }
        }
        return appVersion;
    }
    public  String getAppVersionURL(){

        return  sysAppVersionMapper.getAppVersionURL();
    }
}
